package com.kawaiior.asoulworld.item.weapon;

import com.kawaiior.asoulworld.item.ItemASWeapon;
import com.kawaiior.asoulworld.potion.ModPotions;
import com.kawaiior.asoulworld.util.AsoulWorldUtils;
import com.kawaiior.asoulworld.util.EntityUtil;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.MobEffects;
import net.minecraft.item.EnumAction;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;



public class ItemDianaClassics extends ItemASWeapon {
    public ItemDianaClassics(String name, ToolMaterial material) {
        super(name, material);
        this.useable = true;
        this.attackDamage = 4f;
        this.base_cd = 60f;
        MinecraftForge.EVENT_BUS.register(this);

    }

    @Override
    public int getMaxItemUseDuration(ItemStack stack)
    {
        return 20;
    }

    @Override
    public float getDestroySpeed(ItemStack stack, IBlockState state)
    {
        Block block = state.getBlock();

        if (block == Blocks.WEB)
        {
            return 1.0F;
        }
        else
        {
            Material material = state.getMaterial();
            return material != Material.PLANTS && material != Material.VINE && material != Material.CORAL && material != Material.LEAVES && material != Material.GOURD ? 1.0F : 1.5F;
        }
    }

    @Override
    public int getMaxDamage(ItemStack stack) {
        return 32;
    }

    @Override
    public EnumAction getItemUseAction(ItemStack stack)
    {
        return EnumAction.NONE;
    }

    public void onCreatureStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft)
    {
        if (!worldIn.isRemote)
        {
            EntityUtil.ApplyBuff(entityLiving, MobEffects.INSTANT_HEALTH,0,2);
            EntityUtil.ApplyBuff(entityLiving,MobEffects.HUNGER,1,20);
            EntityUtil.ApplyBuff(entityLiving,MobEffects.FIRE_RESISTANCE,0,20);
            EntityUtil.ApplyBuff(entityLiving,MobEffects.WEAKNESS,1,7);
            stack.damageItem(4, entityLiving);
        }
    }
//    @SubscribeEvent(priority = EventPriority.HIGHEST)
//    public void dianaPortectPlayer (LivingDeathEvent event)
//    {
//        EntityLivingBase living = event.getEntityLiving();
//        if (living.world.isRemote || !(living instanceof EntityPlayer) || living instanceof FakePlayer)
//        {
//            return;
//        }
//        EntityPlayer player = (EntityPlayer)living;
//        if (player.getCooldownTracker().hasCooldown(this))
//        {
//            return;
//        }
//        if (AsoulWorldUtils.consumeInventoryItem(living, s -> s.getItem() == this, 1))
//        {
//            player.setHealth(20);
//            EntityUtil.ApplyBuff(player,MobEffects.REGENERATION,100,2);
//            player.getCooldownTracker().setCooldown(this, 2400);
//            player.sendMessage(new TextComponentTranslation("message.asoulworld.diana_protect_player",null,null));
//        }
//        event.setCanceled(true);
//    }
}
